package com.scorpio.api;

import com.scorpio.appuser.domain.AppUserEntity;
import com.scorpio.basic.vo.OperationIdVo;
import com.scorpio.core.controller.BaseController;
import com.scorpio.core.domain.Result;
import com.scorpio.framework.annotation.Log;
import com.scorpio.framework.annotation.PersonalLogin;
import com.scorpio.framework.annotation.PersonalLoginUser;
import com.scorpio.order.service.OrderService;
import com.scorpio.order.vo.OrderQueryVo;
import com.scorpio.order.vo.PayOrderVo;
import com.scorpio.order.vo.SubmitShopCartOrderVo;
import com.scorpio.order.vo.SubmitShopOrderVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/order")
public class OrderController extends BaseController {

    @Autowired
    private OrderService orderService;

    @Log(title = "提交购物车订单")
    @PostMapping("submitShopCart")
    @PersonalLogin
    public Result submitShopCart(@PersonalLoginUser AppUserEntity user, @Validated @RequestBody SubmitShopCartOrderVo vo) {
        vo.uid = user.getId();
        return Result.success(orderService.submitShopCart(vo));
    }

    @Log(title = "提交商品订单")
    @PostMapping("submitShopOrder")
    @PersonalLogin
    public Result submitShopOrder(@PersonalLoginUser AppUserEntity user, @Validated @RequestBody SubmitShopOrderVo vo) {
        vo.uid = user.getId();
        return Result.success(orderService.submitShopOrder(vo));
    }

    @Log(title = "订单列表查询")
    @GetMapping("orderList")
    @PersonalLogin
    public Result orderList(@PersonalLoginUser AppUserEntity user, @Validated OrderQueryVo vo) {
        vo.uid = user.getId();
        return Result.success(orderService.orderList(vo));
    }

    @Log(title = "订单详情")
    @GetMapping("orderDetails")
    @PersonalLogin
    public Result orderDetails(@PersonalLoginUser AppUserEntity user, @Validated OperationIdVo vo) {
        return Result.success(orderService.orderDetails(user, vo.getId()));
    }


    @Log(title = "下单")
    @PostMapping("placeOrder")
    @PersonalLogin
    public Result placeOrder(@PersonalLoginUser AppUserEntity user, @Validated @RequestBody PayOrderVo vo) {
        return Result.success(orderService.placeOrder(user, vo));
    }
}
